﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace AvmReleaseTool
{
    //private Repo工具设置(依据提供的释放节点信息，生成repo xml文件到指定路径）
    public partial class ExcelReleaseInfoForm : Form, IAvmReleaseInfoDialog
    {
        void IAvmReleaseInfoDialog.SetReleaseCommitInfo(string info)
        {
            
            //this.m_commitInfo = new System.Windows.Forms.TextBox();
            //正则表达式取出要求的信息
            var matches = Regex.Matches(info, @"[\s\S]*?(\n\n|$\n)");

            int index = 0;
            foreach (Match match in matches)
            {
                string git_name = Regex.Match(match.Value.ToString(), @"[\S]*").Value;
                string git_sha = Regex.Match(match.Value.ToString(), @"(?<=\n)[\S]*(?=\n)").Value;

                
                //动态创建控件
                TextBox m_commitInfo = new TextBox();
                m_commitInfo.Name = "tbox" + index.ToString();
                m_commitInfo.ReadOnly = true;
                m_commitInfo.Size = new Size(this.groupBox2.Width - this.m_Info.Right, 20);
                m_commitInfo.Location = new Point(this.m_Info.Right, this.m_Info.Top + 25 * index);
                m_commitInfo.Text = git_name + ":" + git_sha;
                this.groupBox2.Controls.Add(m_commitInfo);
                
                index++;
            }
        }
        void IAvmReleaseInfoDialog.SetReleaseDateInfo(DateTime info)
        {
            //禁止日期控件时间被调整
            this.m_excelReleaseDate.Enabled = false;
            this.m_excelReleaseDate.Value = info;
        }
        void IAvmReleaseInfoDialog.SetReleaseSvnInfo(string info)
        {
            this.m_Info.Text = info;
        }

        void IAvmReleaseInfoDialog.Update()
        {
            this.Show();
        }
        public ExcelReleaseInfoForm()
        {
            InitializeComponent();
        }

        private void ExcelReleaseInfoForm_Load(object sender, EventArgs e)
        {

        }
    }
}
